package com.diy.sigmund.diycommon.test.controller.async;

import com.diy.sigmund.diycommon.entity.ResultMsg;
import com.diy.sigmund.diycommon.entity.po.user.UserAuth;
import com.diy.sigmund.diycommon.test.service.async.AsyncTaskTestService;
import java.util.concurrent.Future;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ylm-sigmund
 * @since 2022/7/10 13:21
 */
@RestController
@RequestMapping("")
public class AsyncTestController {

    @Autowired
    private AsyncTaskTestService asyncTaskTestService;

    private static final Logger log = LoggerFactory.getLogger(AsyncTestController.class);

    @PostMapping("/testSome/testAsync")
    public ResultMsg testAsync() throws Exception {
        UserAuth userAuth = new UserAuth();
        userAuth.setId("123456");
        userAuth.setIdentifier("钢管男");
        asyncTaskTestService.testPrint(userAuth);
        return ResultMsg.success();
    }

    @PostMapping("/testSome/testAsyncFuture")
    public ResultMsg testAsyncFuture() throws Exception {
        UserAuth userAuth = new UserAuth();
        userAuth.setId("123456");
        userAuth.setIdentifier("钢管男");
        Future<ResultMsg> resultMsgFuture = asyncTaskTestService.testFuture(userAuth);
        return resultMsgFuture.get();
    }

    @PostMapping("/user/testAsyncContextHolder")
    public ResultMsg testAsyncContextHolder() throws Exception {
        UserAuth userAuth = new UserAuth();
        userAuth.setId("123456");
        userAuth.setIdentifier("钢管男");
        asyncTaskTestService.testAsyncContextHolder(userAuth);
        asyncTaskTestService.testFuture(userAuth);
        return ResultMsg.success();
    }

}
